package org.class2table;

import org.class2table.core.dictionary.DefaultRule;
import org.class2table.core.util.DataSourceUtil;
import org.class2table.export.ExportProcessor;
import org.class2table.sync.CompareProcessor;
import org.class2table.sync.CompareResultsUtil;
import org.class2table.sync.SyncExecutor;
import org.class2table.sync.bean.CompareResult;
import org.class2table.z_running_data.DefaultSyncData;
import org.class2table.z_running_data.DefaultExportData;
import org.junit.Test;

import java.util.List;

public class App {

    @Test
    public void testSync() {
        CompareProcessor.init(
                DefaultSyncData.masterConnection,
                DefaultSyncData.tenantConnectionMap.keySet(),
                DefaultSyncData.inputClazz,
                DefaultRule.CLAZZ_2_COLUMN_TYPE_RULE_MAP
        );
        List<CompareResult> compareResults = CompareProcessor.compare();
        CompareResultsUtil.printCompareResults(compareResults);

        SyncExecutor.init(DefaultSyncData.tenantConnectionMap);
        SyncExecutor.exeSync(compareResults);

        DataSourceUtil.release();
    }

    @Test
    public void testExport() {
        ExportProcessor.init(
                DefaultExportData.exportTableList,
                DefaultExportData.savePath,
                DefaultExportData.exportConnection,
                DefaultExportData.dbName,
                DefaultRule.DATA_TYPE_2_CLAZZ_RULE_MAP
        );
        ExportProcessor.export();
        DataSourceUtil.release();
    }

}